#include<iostream>
#include<queue>
using namespace std;
const int N = 1010;
typedef pair<int, int> PII;
#define x first
#define y second
bool st[N][N];
queue<PII>q;
int n, m;
char mp[N][N];

void bfs(int x, int y)
{
	int hh = 0;
	int tt = 0;
	q[0] = { x,y };
	st[x][y] = 1;
	while (hh <= tt) {
		PII temp = q[hh++];
		for (int i = temp.first - 1; i <= temp.first + 1; i++) {
			for (int j = temp.second - 1; j <= temp.second + 1; j++) {
				if (i == temp.first && j == temp.second)continue;
				if (i < 0 || i >= n || j < 0 || j >= m)continue;
				if (map[i][j] == '.' || st[i][j])continue;
				st[i][j] = 1;
				q[++tt] = { i,j };
			}
		}
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> mp[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!st[i][j] && mp[i][j] == 'W') {
				bfs(i, j);
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}	